import net from 'net';

const html = `<h1>tcp server</h1>`
const responseHeaders = [
  'HTTP/1.1 200 OK',
  'Content-Type: text/html',
  'Content-Length: ' + html.length,
  '\r\n',
  html
]

const http = net.createServer((socket) => {
  socket.on('data', (data) => {
    if (/GET/.test(data.toString())) {
      socket.write(responseHeaders.join('\r\n'))
      socket.end()
    }
    console.log('server Received data:', data.toString());
  });
});

http.listen(3000, () => {
  console.log('Server is running on port 3000');
});